-- Globals
operationFileName = "campaigns/Operation Ghost.lua"
campaignFileName = nil
currentLevel = 1

levelFileNames = { "levels/Hello.lvl", "levels/test2.lvl" }
levelCount = 2

function NewCampaign(fileName)
	campaignFileName = fileName
	Save()
end

function LoadCampaign(fileName)
	campaignFileName = fileName
	Load()
end

function PlayCampaign()
	while currentLevel <= levelCount do
		dbSetLevelFileName(levelFileNames[currentLevel])
		
		levelCompleted = false
		dbPlayLevel()
		
		if levelCompleted then
			currentLevel = currentLevel + 1
			
			Save()
			
			local result = dbDoMessageBox("Level Completed!", "Play next level or return to main menu?", "Next Level", "Main Menu", nil)
			if result == 2 then
				break
			end
		else
			local result = dbDoMessageBox("Level Failed!", "Retry level or return to main menu?", "Retry Level", "Main Menu", nil)
			if result == 2 then
				break
			end
		end
	end
end

function Load()
	file = io.open(campaignFileName, "r")
	operationFileName = file:read();
	currentLevel = file:read("*n");
	io.close(file)
end

function Save()
	file = io.open(campaignFileName, "w+")
	file:write(operationFileName, "\n");
	file:write(currentLevel);
	io.close(file)
end
